Back to course home
0% completed
Vote For New Content
Oracle Hard
Integer to English Words (hard)
Solution: Integer to English Words
Trapping Rain Water (hard)
Solution: Trapping Rain Water
First Missing Positive (hard)
Solution: First Missing Positive
Merge K Sorted Lists (hard)
Solution: Merge K Sorted Lists
Max Points on a Line (hard)
Solution: Max Points on a Line
Sudoku Solver (hard)
Solution: Sudoku Solver
Longest Valid Parentheses (hard)
Solution: Longest Valid Parentheses
Remove Nth Node From End of List (Medium)
Solution: Remove Nth Node From End of List
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Constrained Subsequence Sum (hard)
Solution: Constrained Subsequence Sum
Minimize Maximum of Array (medium)
Problem Statement
Given a positive integer array nums, return the minimum possible value of the maximum integer of nums after performing multiple operations.
In one operation, you must:
- Select any index
isuch that1 <= i < nandnums[i] > 0. - Increase
nums[i - 1]by1. - Decrease
nums[i]by1.
Examples
Example 1:
- Input: nums =
[4, 5, 3, 2, 1, 6] - Expected Output:
5 - Justification: We can perform operations to decrease the last element (6) to 5 and increase the fifth element to 2. Here, the maximum array element is 5.
Example 2:
- Input: nums =
[1, 2, 3, 4] - Expected Output:
3 - Justification: We can decrease the last element (4) to 3 and increase the third element to 4, then decrease the third element (now 4) to 3, increasing the second element to 3. The array becomes [1, 3, 3, 3], with the maximum being 3.
Example 3:
- Input: nums =
[8, 2, 2, 3] - Expected Output:
8 - Justification: We can't perform any operation to minimize the maximum value of the array. So,
8is the minimum possible value of the maximum integer.
Try it yourself
Try solving this question here:
Java
. . . .
Solution: Search a 2D Matrix II
Solution: Minimize Maximum of Array
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself